#pragma once
#ifndef GRAMMAR_H
#define GRAMMAR_H

#include "headers.h"

/** struct **/
struct Rule
{
    QString LHS;
    QStringList RHS;
    Rule(QString lhs, QStringList rhs)
    {
        LHS=lhs;
        RHS=rhs;
    }
    QString toString() const
    {
        QString result=LHS+" ->";
        foreach(QString str, RHS)
            result.append(" "+str);
        return result;
    }
    bool operator==(Rule ruleParam)
    {
        if(LHS==ruleParam.LHS && RHS==ruleParam.RHS)
            return true;
        return false;
    }
};

class Grammar
{
    friend class ParserGenerator;

public:
    bool ReadFromXML(QString fileName);
    bool isEmpty();
    /** methods for output **/
    QStringList getNonterminals();
    QStringList getTerminals();
    QStringList getRules();
    QString getFirstSymbol();
    /** ****************** **/

private:
    QSet<QString> nonterminals;
    QSet<QString> terminals;
    QList<Rule> rules;
    QString firstSymbol;
};

#endif // GRAMMAR_H
